layui.define(function(exports){
	var doing =function(e){
		if(typeof $(e) !==  "object"){
			console.error("this DOM is not a banner_Object!");
			return false;
		}
		var $this=$(e)
		,$pageBox = $this
		,$pageSlide = $pageBox.find(".slideBox .pageSlide")
		,$prevBtn = $pageBox.find(".prevBtn")
		,$nextBtn = $pageBox.find(".nextBtn")
		,$pointLiList = $pageBox.find(".pointList li")
		,len = $pageSlide.length
		,currentIndex = 0;
		
		for(var i = 0; i < len; i++) {
			$pageSlide.eq(i).css("z-index", len - i);
		}
		$pointLiList.on("click", function() {
			currentIndex = $(this).index();
			$(this).addClass("active").siblings().removeClass("active");
			$pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
		});
		$nextBtn.on("click", function() {
//			console.dir(new Date()+timer);
			currentIndex++;
			if(currentIndex == len)currentIndex = 0;
			$pointLiList.eq(currentIndex).addClass("active").siblings().removeClass("active");
			$pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
		});
		$prevBtn.on("click", function() {
			currentIndex--;
			if(currentIndex == -1)currentIndex = len - 1;
			$pointLiList.eq(currentIndex).addClass("active").siblings().removeClass("active");
			$pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
		});
		var timer=null;
		var $img = $pageSlide.find("img").eq(0);
//		console.dir($img.height());
		if($img.height()){
			$pageSlide.find("img").css("display","block");
			timer=setInterval(function(){
                currentIndex++;
                if(currentIndex == len)currentIndex = 0;
                $pointLiList.eq(currentIndex).addClass("active").siblings().removeClass("active");
                $pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
			},3000);
		}else{
			$img.on("load",function(){
				$pageSlide.find("img").css("display","block");
				timer=setInterval(function(){
                    currentIndex++;
                    if(currentIndex == len)currentIndex = 0;
                    $pointLiList.eq(currentIndex).addClass("active").siblings().removeClass("active");
                    $pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
				},3000);
			});
		}
		
		$pageSlide.on("mouseenter",function(){
			clearInterval(timer);
		});
		$pageSlide.on("mouseout",function(){
			timer=setInterval(function(){
				$pageSlide.find("img").css("display","block");
                currentIndex++;
                if(currentIndex == len)currentIndex = 0;
                $pointLiList.eq(currentIndex).addClass("active").siblings().removeClass("active");
                $pageSlide.eq(currentIndex).fadeIn().siblings().fadeOut();
			},3000);
		});
	};
		
	exports('Zbanner',doing); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});    